package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import playerio.*;
	
	public class Main extends Sprite 
	{
		public const BOARD_X:int = 800 / 2 - 100;
		public const BOARD_Y:int = 600 / 2;
		
		static public var brd:board;
		static public var mainroom_symb:mainroom;
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			PlayerIO.connect(
				stage,								//Referance to stage
				"vgs-xxmkjdq6rkatgytlweg0ew",			//Game id (Get your own at playerio.com)
				"public",							//Connection id, default is public
				"GuestUser",						//Username
				"",									//User auth. Can be left blank if authentication is disabled on connection
				null,								//Current PartnerPay partner.
				onConnect,							//Function executed on successful connect
				onConnectError						//Function executed if we recive an error
			);   
			/*brd = new board(19, BOARD_X, BOARD_Y);
			addChild(brd);*/
			/*var r:room = new room();
			addChild(r);*/
		}	
		
		public function onConnect(client:Client):void 
		{
			//client.multiplayer.developmentServer = "localhost:8184";
			trace("onConnect");
			//Create pr join the room test
			client.multiplayer.createJoinRoom(
				"mainroom",							//Room id. If set to null a random roomid is used
				"Main Server Room",					//The game type started on the server
				true,								//Should the room be visible in the lobby?
				{},									//Room data. This data is returned to lobby list. Variabels can be modifed on the server
				{},									//User join data
				handleJoin,							//Function executed on successful joining of the room
				handleJoinError						//Function executed if we got a join error
			);
		}
		
		public function handleJoin(connection:Connection):void 
		{
			mainroom_symb = new mainroom(connection);
			addChild(mainroom_symb);
		}
		
		public function handleJoinError(error:PlayerIOError):void 
		{
			trace("handleJoinError")
		}
		
		public function onConnectError(error:PlayerIOError):void 
		{
			trace("onConnectError")
		}
	}
	
}